<template>
  <div>
    <el-input placeholder="点击按钮开窗选择" :disabled="true" v-model="textField" class="input-with-select">
      <el-button slot="append" @click="pickerVisible = true" icon="el-icon-search"></el-button>
    </el-input>
    <el-dialog :visible.sync="pickerVisible" :append-to-body="true" :modal="false">
      <DimensionPicker
        :production="production"
        :level="level"
        :init="selected"
        :autoset="true"
        @confirm="updateCell"
        @ignore="pickerVisible=false"
      />
    </el-dialog>
  </div>
</template>
<script>
import Vue from 'vue'
import DimensionPicker from '@/components/DataPicker/DimensionPicker.vue'
import { getDimensionDoc } from '@/api/dimension'
export default {
  components: { DimensionPicker },

  data() {
    return {
      textField: '',
      valueField: 0,
      cancelBeforeStart: true,
      pickerVisible: false,
      selected: [],
      level: null,
      production: null
    }
  },
  methods: {
    getValue() {
      return this.valueField
    },
    isCancelBeforeStart() {
      if (this.params.conditions) {
        this.level = this.params.conditions.level
        this.production = this.params.conditions.production
      }

      return this.cancelBeforeStart
    },
    updateCell(params) {
      this.valueField = params[0].AutoId
      this.textField = params[0].Name
      this.pickerVisible = false
      this.$emit('confirm', params[0])
    }
  },
  created() {
    this.cancelBeforeStart = false
  },
  mounted() {
    if (this.params.value) {
      this.valueField = this.params.value
      this.selected.push(this.valueField)
      getDimensionDoc(this.params.value)
        .then(response => {
          if (response.Result === 0 && response.Data) {
            this.textField = response.Data.Name
          } else {
            this.textField = '未知'
          }
        })
        .catch(error => {
          console.log(error)
        })
    }
  }
}
</script>
